<template>
  <teleport :to="root">
    <div class="background" @click.self="() => (closeAction && closeAction()) || $emit('click:around')">
      <div class="container">
        <div v-if="!hideClose" class="close" @click="() => (closeAction && closeAction()) || $emit('click:close')">
          <Icon name="close" size="20"></Icon>
        </div>
        <slot></slot>
      </div>
    </div>
  </teleport>
</template>
<script setup>
defineEmits(['click:around', 'click:close'])

defineProps({
  root: { type: String, default: 'body' },
  hideClose: { type: Boolean, default: false },
  closeAction: { type: Function, default: undefined },
})
</script>
<style scoped lang="scss">
.background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 1;

  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  width: 80%;
  max-width: 18.75rem;
  position: relative;
  background-color: rgb(var(--v-theme-surface));
  padding: 1rem;
  border-radius: 0.625rem;

  display: flex;
  justify-content: center;
  align-items: center;
}

.close {
  position: absolute;
  top: 0;
  right: 0;
  cursor: pointer;

  padding-right: 0.5rem;
  padding-top: 0.5rem;
}
</style>
